package command;

import java.util.HashMap;

public class ConditionNode {
	private String _operator;
	private ConditionNode _left;
	private ConditionNode _right;
	
	public ConditionNode() {
		
	}
	
	public ConditionNode(String op,ConditionNode l,ConditionNode r){
		this._operator = op;
		this._left = l;
		this._right = r;
	}
	
	public String toString() {
		String a;
		a = "Operator: " + _operator + "\n";
		a += "Left:" +   _left.toString()+ "\n";
		a += "Right:" + _right.toString()+ "\n";
		return a;
	}
	
	public Boolean eval(HashMap<String,String> row) {
		if(_operator.equalsIgnoreCase("and"))
			return _left.eval(row) && _right.eval(row);
		
		if(_operator.equalsIgnoreCase("or"))
			return _left.eval(row) || _right.eval(row);
		

		if(_operator.equalsIgnoreCase("not"))
			return !_left.eval(row);
		return false;
	}
}
